<template>
  <div>
    <en-table-layout
      pagination
      :tableData="tableData"
      :loading="loading"
      @selection-change="handleSelectionChange">
      <div slot="toolbar" class="inner-toolbar">
        <div class="toolbar-btns">
          <el-button type="primary" @click="enableClick(1)">启用</el-button>
          <el-button type="primary" @click="enableClick(0)">禁用</el-button>
          <el-button type="primary" @click="updateLeader">修改上级团长</el-button>
        </div>
        <div class="toolbar-search">
          <div class="cityAddr">
            <span>
              所属城市:
            </span>
            <dg-select
              dictType="CITY_ADDRES"
              clearable
              placeholder="请选择"
              v-model="advancedForm.city"
              :defaultValue="advancedForm.city"
              @change="advancedSearchEvent"
            ></dg-select>
          </div>
          <en-table-search
          @search="searchEvent"
          @advancedSearch="advancedSearchEvent"
          advanced
          placeholder="请输入姓名">
            <template slot="advanced-content">
              <el-form
              ref="advancedForm"
              :model="advancedForm"
              label-width="80px">
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="会员昵称:" class="toolbar-input" prop="nick_name">
                      <el-input v-model="advancedForm.nick_name" placeholder="请输入会员昵称" clearable></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="团长等级:" class="toolbar-input" prop="distributor_title">
                      <el-select v-model="advancedForm.distributor_title" placeholder="请输入团长等级" clearable>
                        <el-option label="运营经理" value="1"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="审核状态:" class="toolbar-input" prop="audit_status">
                      <el-select v-model="advancedForm.audit_status" placeholder="请输入审核状态" clearable>
                        <el-option label="审核申请中" value="1"></el-option>
                        <el-option label="审核通过" value="2"></el-option>
                        <el-option label="审核不通过" value="3"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="团长手机:" class="toolbar-input" prop="mobile">
                      <el-input v-model="advancedForm.mobile" placeholder="请输入团长手机" clearable></el-input>
                    </el-form-item>
                  </el-col>
                    <el-col :span="12">
                    <el-form-item label="上级团长:" class="toolbar-input" prop="lv1_real_name">
                      <el-input v-model="advancedForm.lv1_real_name" placeholder="请输入上级团长" clearable></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="结算模式:" class="toolbar-input" prop="settle_mode">
                      <dg-select dictType="settle_mode" clearable placeholder="请选择" v-model="advancedForm.settle_mode" :defaultValue="advancedForm.settle_mode" ></dg-select>
                    </el-form-item>
                  </el-col>
                    <el-col :span="12">
                    <el-form-item label="业务类型:" class="toolbar-input" prop="business_type">
                      <dg-select dictType="business_type" clearable placeholder="请选择" v-model="advancedForm.business_type" :defaultValue="advancedForm.business_type" ></dg-select>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </template>
          </en-table-search>
        </div>
      </div>
      <template slot="table-columns">
        <el-table-column type="selection" min-width="55" />
        <el-table-column prop="real_name" min-width="80" label="姓名"/>
        <!-- 审核状态 -->
        <el-table-column label="审核状态" min-width="80">
          <template slot-scope="scope">
            <span>{{s_audit_status[scope.row.audit_status]}}</span>
          </template>
        </el-table-column>
        <el-table-column label="结算模式" min-width="80">
          <template slot-scope="scope">
            <span>{{scope.row.settle_mode | filterDict('settle_mode')}}</span>
          </template>
        </el-table-column>
        <el-table-column label="业务类型" min-width="80">
          <template slot-scope="scope">
            <span>{{scope.row. business_type | filterDict(' business_type')}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="team_name" min-width="100" label="团号"/>
        <el-table-column prop="invite_code" min-width="80" label="团长邀请码"/>
        <el-table-column prop="status" min-width="80" label="团长状态">
          <template slot-scope="scope">
            <span>{{scope.row.status === 1  ? '启用' : '禁用'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="nick_name" min-width="80" label="会员昵称"/>
        <el-table-column prop="midentity" min-width="150" label="身份证号"/>
        <el-table-column prop="distributor_title" min-width="80" label="团长等级"/>
        <!-- <el-table-column prop="distributorTitle" min-width="80" label="团长名称"/> -->
        <el-table-column min-width="180" label="上级团长">
          <template slot-scope="scope">
            <span>{{scope.row.lv1_invite_code || ''}} /{{scope.row.lv1_real_name || ''}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="" min-width="150" label="所属地区">
          <template slot-scope="{ row }">
            <span>{{row.province}} {{row.city}} {{row.county}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="address" min-width="100" label="详细地址"/>
        <el-table-column prop="mobile" min-width="100" label="手机号"/>
        <el-table-column prop="audit_time" min-width="140" label="审核时间">
          <template slot-scope="{row}">
            <span>{{row.audit_time| unixToDate('yyyy-MM-dd hh:mm:ss')}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" min-width="140" label="申请时间">
          <template slot-scope="{row}">
            <span>{{row.create_time| unixToDate('yyyy-MM-dd hh:mm:ss')}}</span>
          </template>
        </el-table-column>
        <!--人数-->
        <el-table-column prop="downline" min-width="80" label="人数"/>
        <!--销售金额-->
        <el-table-column label="销售金额">
          <template slot-scope="scope">{{ scope.row.turnover_price | unitPrice('￥') }}</template>
        </el-table-column>
        <!--利润额-->
        <el-table-column label="利润额">
          <template slot-scope="scope">{{ scope.row.rebate_total | unitPrice('￥') }}</template>
        </el-table-column>
        <!--订单数	-->
        <el-table-column prop="order_num" label="订单数	"/>
        <!--提成模板	-->
        <el-table-column prop="current_tpl_name" label="提成模板	"/>
        <!--注册时间-->
        <!-- <el-table-column prop="create_time" :formatter="MixinUnixToDate" min-width="150" label="注册时间"/>

        </el-table-column> -->
        <!-- 审核状态 -->
        <el-table-column prop="apply_reason" min-width="180" label="申请原因" />
        <el-table-column prop="audit_remark" min-width="180" label="审核备注"/>
        <el-table-column label="操作" min-width="290" fixed="right">
          <template slot-scope="scope" >
            <el-button size="mini" type="primary" @click="reviewLeader(scope.row)" v-if="scope.row.audit_status===1">审核</el-button>
            <el-button size="mini" type="primary" @click="auditLeader(scope.row)" v-if="scope.row.audit_status === 2  && scope.row.status === 1">修改</el-button>
            <el-button size="mini" type="primary" @click="handleTurnoverStatistics(scope.row)">营业额统计</el-button>
            <el-button size="mini" type="primary" @click="handleProfitStatistics(scope.row)">利润额统计</el-button>
            <!-- <el-button type="primary" @click="handleLeader(scope.row)">修改</el-button> -->
            <!-- <el-button type="danger" @click="deleteLeaderList(scope.row)">删除</el-button> -->
          </template>
        </el-table-column>
        <!--修改模式-->
        <!-- <el-table-column label="修改模版" width="100">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="handleEditTpl(scope.row)">修改模版</el-button>
          </template>
        </el-table-column> -->
        <!--营业额统计-->
      </template>
      <el-pagination
        v-if="tableData"
        slot="pagination"
        @size-change="handlePageSizeChange"
        @current-change="handlePageCurrentChange"
        :current-page="pageData.page_no"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageData.page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageData.data_total">
      </el-pagination>
    </en-table-layout>
    <el-dialog :title="`${currentRow.name}的修改模式`" width="40%" :visible.sync="isShowModifyModel" class="modify-model">
      <en-table-layout
        pagination
        border
        :tableData="gridData"
        style="overflow: hidden">
        <template slot="table-columns">
          <el-table-column label="模板ID" width="150">
            <template slot-scope="scope">
              <el-radio :label="scope.row.id" v-model="currentRow.current_tpl_id"></el-radio>
            </template>
          </el-table-column>
          <el-table-column property="tpl_name" label="模板名"></el-table-column>
          <el-table-column property="tpl_describe" label="说明"></el-table-column>
        </template>
        <el-pagination
          v-if="gridData"
          slot="pagination"
          @size-change="handleGridPageSizeChange"
          @current-change="handleGridPageCurrentChange"
          :current-page="pageGridData.page_no"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageGridData.page_size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageGridData.data_total">
        </el-pagination>
      </en-table-layout>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="reserveTpl">保 存</el-button>
      </div>
    </el-dialog>

    <el-dialog title="审核" width="40%" :visible.sync="auditDialog" class="modify-model">
      <el-form
        ref="riderForm"
        class="riderForm"
        label-width="100px"
        size="small"
        :model="auditForm">
        <el-form-item  label="审核意见：" prop="status">
          <el-radio-group v-model="auditForm.status">
            <el-radio :label="2">审核通过</el-radio>
            <el-radio :label="3">审核驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item  label="审核备注：" prop="refuseReason">
          <el-input type="textarea" height="200px" v-model="auditForm.refuseReason" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer mt5">
        <el-button size="small" type="primary"  @click="submitAudit()">确 定</el-button>
        <el-button size="small" @click="auditDialog=false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="修改上级团长" width="40%" :visible.sync="updateLeaderDialog" >
      <el-form
        label-width="100px"
        size="small"
        :model="auditForm">
        <div class="updat-dialoge">温馨提示：已选中{{multipleSelection.length}}条记录进行上级团长修改！</div>
        <el-form-item label="上级团长" class="toolbar-input" prop="ship_name">
          <el-select
            v-model="leaderForm.member_id"
            filterable
            remote
            placeholder="上级团长"
            clearable
            :remote-method="remoteMethod"
            :loading="remote_loading"
            class="myselect-type"
            >
            <el-option
              v-for="item in options"
              :key="item.member_id"
              :label="item.invite_code+'-'+item.real_name+'-'+item.mobile"
              :value="item.member_id"
              >
              <div class="my-option">
                <span>{{item.invite_code}}</span>
                <span>{{item.real_name}}</span>
                <span class="mobile">{{item.mobile}}</span>
              </div>
            </el-option>
          </el-select>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer mt5">
        <el-button size="small" type="primary"  @click="submitLeader()">确 定</el-button>
        <el-button size="small" @click="updateLeaderDialog=false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="团长审核" :visible.sync="reviewLeaderDialog" width="600px">
      <el-form ref="reviewLeaderForm" :model="reviewLeaderForm" label-width="100px" :rules="reviewLeaderFormRules">
        <el-form-item label="审核意见:">
          <el-radio-group v-model="reviewLeaderForm.audit_status" @change="handleReviewChange()">
            <el-radio label="2">审核通过</el-radio>
            <el-radio label="3">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="团长别名:" v-if="Review" prop="teamName">
          <el-input v-model="reviewLeaderForm.teamName" placeholder="给团长一个别称吧, 如: 8团, 必填 "></el-input>
        </el-form-item>
        <el-row v-if="Review">
          <el-col :span="14">
            <el-form-item label="团长地址:" prop="index_region">
              <en-region-picker
                :api="MixinRegionApi"
                @changed="(object) => { reviewLeaderForm.index_region = object.last_id }"
                class="select-get"
                clearable
              ></en-region-picker>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-input placeholder="请输入详细地址, 选填" v-model="reviewLeaderForm.address"></el-input>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12" v-if="Review">
            <el-form-item label="结算模式:" prop="settle_mode">
              <dg-select dictType="settle_mode" clearable placeholder="请选择" v-model="reviewLeaderForm.settle_mode" :defaultValue="reviewLeaderForm.settle_mode" ></dg-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="Review">
            <el-form-item label="业务类型:" prop="business_type">
              <dg-select dictType="business_type" clearable placeholder="请选择" v-model="reviewLeaderForm.business_type" :defaultValue="reviewLeaderForm.business_type" ></dg-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="覆盖区域:" v-if="Review" prop="operate_areas">
          <el-input v-model="reviewLeaderForm.operate_areas" placeholder="填写覆盖区域"></el-input>
        </el-form-item>
        <el-form-item label="群人数:" v-if="Review" prop="wechat_groups_num">
          <el-input-number v-model="reviewLeaderForm.wechat_groups_num" :min="1" :max="9999999999" label="填写微信群人数"></el-input-number>
        </el-form-item>
        <el-form-item label="审核备注:">
          <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 6}" v-model="reviewLeaderForm.refuse_reason"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="clearReviewLeader('reviewLeaderForm')">取 消</el-button>
        <el-button type="primary" @click="handleClick('reviewLeaderForm')">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="修改团长信息" :visible.sync="auditLeaderDialog" width="600px">
      <el-form ref="auditLeaderForm" :model="auditLeaderForm" label-width="100px" :rules="auditLeaderFormRules">
        <el-form-item v-show="false" >
          <el-input type="hidden" v-model="auditLeaderForm.id"></el-input>
        </el-form-item>
        <el-form-item label="团长别名:"  prop="team_name">
          <el-input v-model="auditLeaderForm.team_name" placeholder="给团长一个别称吧, 如: 8团, 必填 "></el-input>
        </el-form-item>
        <el-row >
          <el-col :span="14">
            <el-form-item label="团长地址:" prop="index_region">
              <en-region-picker
                :api="MixinRegionApi"
                :default="areas"
                @changed="(object) => { auditLeaderForm.index_region = object.last_id }"
                clearable
              ></en-region-picker>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-input placeholder="请输入详细地址, 选填" v-model="auditLeaderForm.address"></el-input>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="结算模式:" prop="settle_mode">
              <dg-select dictType="settle_mode" clearable placeholder="请选择" v-model="auditLeaderForm.settle_mode" :defaultValue="auditLeaderForm.settle_mode" ></dg-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务类型:" prop="business_type">
              <dg-select dictType="business_type" clearable placeholder="请选择" v-model="auditLeaderForm.business_type" :defaultValue="auditLeaderForm.business_type" ></dg-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="覆盖区域:" v-if="Review" prop="operate_areas">
          <el-input v-model="auditLeaderForm.operate_areas" placeholder="填写覆盖区域"></el-input>
        </el-form-item>
        <el-form-item label="群人数:" v-if="Review" prop="wechat_groups_num">
          <el-input-number v-model="auditLeaderForm.wechat_groups_num" :min="1" :max="9999999999" label="填写微信群人数"></el-input-number>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="auditLeaderDialog = false ">取 消</el-button>
        <el-button type="primary" @click="auditLeaderClick('auditLeaderForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import * as API_distribution from '@/api/distribution'
  import dataJson from '@/api/citys.json'
  import { getDictData, filterShowDict } from '@/common/filter-show';
  export default {
    name: 'distributor-list',
    data() {
      return {
        // 列表loading状态
        loading: false,
        radio: '2',
        // 列表参数
        params: {
          page_no: 1,
          page_size: 10
        },
        // 列表数据
        tableData: [],

        /** 分页信息 */
        pageData: {},

        /** 是否显示修改模式 */
        isShowModifyModel: false,

        /** 修改模式模板列表 */
        gridData: [],

        /** 修改模式分页 */
        pageGridData: {},

        /** 当前操作分销商 */
        currentRow: {},
        cityOptions: [],
        /** 参数 */
        gridParams: {},
        memberId: [],
        Review: true,
        multipleSelection: [],
        auditDialog: false,
        updateLeaderDialog: false,
        reviewLeaderDialog: false,
        auditLeaderDialog: false,
        auditForm: {
          status: '',
          refuseReason: '',
          id: ''
        },
        areas: [],
        reviewLeaderForm: {
          member_id: '',
          audit_status: '2',
          business_type: '',
          settle_mode: '',
          teamName: '',
          index_region: null,
          operate_areas: '',
          wechat_groups_num: '',
          refuse_reason: ''
        },
        auditLeaderForm: {
          member_id: '',
          teamName: '',
          operate_areas: '',
          settle_mode: '',
          business_type: '',
          wechat_groups_num: '',
          index_region: null
        },
        s_audit_status: ['未申请', '已申请', '通过', '不通过'],
        options: [],
        remote_loading: false,
        leaderForm: {
          member_id: ''
        },
        // 模糊查询表单
        advancedForm: {},
        auditLeaderFormRules: {
          team_name: [
            {
              required: true,
              message: '请输入团号',
              trigger: 'blur'
            }
          ],
          settle_mode: [
            {
              required: true,
              message: '请输入结算方式',
              trigger: 'change'
            }
          ],
          business_type: [
            {
              required: true,
              message: '请输入业务类型',
              trigger: 'change'
            }
          ],
          wechat_groups_num: [
            {
              required: false,
              message: '请输入数字',
              trigger: 'blur'
            }
          ],
          index_region: [
            {
              required: true,
              message: '请选择团长地址',
              trigger: 'blur'
            }
          ]
        },
        reviewLeaderFormRules: {
          teamName: [
            {
              required: true,
              message: '请输入团号',
              trigger: 'blur'
            }
          ],
          settle_mode: [
            {
              required: true,
              message: '请输入结算方式',
              trigger: 'change'
            }
          ],
          business_type: [
            {
              required: true,
              message: '请输入业务类型',
              trigger: 'change'
            }
          ],
          index_region: [
            {
              required: true,
              message: '请选择团长地址',
              trigger: 'blur'
            }
          ]
        }

      }
    },
    filters: {
      // 字典显示转换
      filterDict (_stateVal, _dictType) {
        return filterShowDict(_dictType, _stateVal);
      }
    },
    mounted() {
      // 获取格式化字典数据
      getDictData('settle_mode');
      getDictData('business_type');
      this.GET_DistributorList();
      this.cityOptions = dataJson
    },
    methods: {
      /**
        * @date 2020/08/26
        * @author kjh
        * @description {修改上级团长发送请求}
      */
      submitLeader() {
        let _stringMemberId = this.memberId.toString();
        let _params = {
          member_ids: _stringMemberId,
          member_id_lv1: this.leaderForm.member_id
        };
        this.loading = true;
        API_distribution.updateLeaderList(_params).then(response => {
          this.loading = false;
          this.GET_DistributorList();
        })
          .catch(() => {
            this.loading = false;
          });
        this.updateLeaderDialog = false;
        this.leaderForm.member_id = undefined;
        this.$message.success('操作成功');
      },
      /**
        * @date 2020/08/26
        * @author kjh
        * @description {远程搜索}
      */
      remoteMethod(query) {
        if (query !== '') {
          this.getLeaderList(query);
        } else {
          this.options = [];
        }
      },
      /**
        * @date 2020/08/26
        * @author kjh
        * @description {远程搜索需要的查询团长信息}
      */
      getLeaderList(query) {
        this.remote_loading = true;
        let _params = {
          key_words: query
        };
        API_distribution.apiGetLeaderList(_params)
          .then(response => {
            this.remote_loading = false;
            this.options = response.data;
          })
          .catch(() => {
            this.remote_loading = false;
          });
      },
      /**
        * @date 2020/08/26
        * @author kjh
        * @description {触发修改团长弹框}
      */
      updateLeader() {
        if (!this.multipleSelection.length) {
          this.$message.warning(`请选择团长！`);
          return;
        }
        this.memberId = [];
        this.multipleSelection.forEach(item => {
          this.memberId.push(item.id);
        });
        this.updateLeaderDialog = true;
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },

      /**
        * @date 2020/08/28
        * @author kaiqiang
        * @description { 禁用与启用 }
      */
      enableClick(state) {
        if (!this.multipleSelection.length) {
          this.$message.warning('请选择团长!');
          return
        }
        let ids = [];
        for (let item of this.multipleSelection) {
          ids.push(item.id);
        }
        if (ids.length > 0) {
          let params = {
            'distribution_ids': ids.toString(),
            status: state
          };
          API_distribution.OpenOrClose(params).then((response) => {
            this.$message.success(response.message);
            this.GET_DistributorList();
          })
        }
      },
      /**
        * @date 2020/08/22
        * @author kjh
        * @description {审核弹框}
      */
      auditIt(row) {
        this.auditDialog = true;
        this.auditForm.id = row.id;
      },
      /**
        * @date 2020/08/22
        * @author kjh
        * @description {审核通过提交请求}
      */
      submitAudit() {
        this.loading = true;
        let _params = {
          member_id: this.auditForm.id,
          audit_status: this.auditForm.status,
          refuse_reason: this.auditForm.refuseReason
        };
        API_distribution.auditDistributor(_params).then(response => {
          this.loading = false;
          this.auditDialog = false;
          this.$message.success(response.message);
          this.GET_DistributorList();
        });
        this.loading = false;
      },
      /** 分页大小发生改变 */
      handlePageSizeChange(size) {
        this.params.page_size = size
        this.GET_DistributorList()
      },

      /** 分页页数发生改变 */
      handlePageCurrentChange(page) {
        this.params.page_no = page
        this.GET_DistributorList()
      },

      /** 搜索事件触发 */
      searchEvent(data) {
        this.params = {
          page_no: 1,
          page_size: 10,
          real_name: data
        }
        this.GET_DistributorList()
      },
      // 高级搜索按钮的点击事件
      advancedSearchEvent() {
        this.params = {
          ...this.params,
          ...this.advancedForm
        }
        console.log(this.params)
        this.params.page_no = 1
        this.GET_DistributorList()
      },
      /** 获取个人分销商列表 */
      GET_DistributorList() {
        this.loading = true
        API_distribution.getDistributorList(this.params).then(response => {
          this.loading = false
          this.tableData = response.data
          this.pageData = {
            page_no: response.page_no,
            page_size: response.page_size,
            data_total: response.data_total
          }
        })
      },

      /** 修改模式 */
      handleEditTpl(row) {
        this.isShowModifyModel = true
        this.currentRow = row
        this.GET_PerAccomplishmentTpl()
      },

      /** 获取模板列表 */
      GET_PerAccomplishmentTpl() {
        API_distribution.getPerAccomplishmentTpl(this.gridParams).then(response => {
          this.gridData = response.data
          this.pageGridData = {
            page_no: response.page_no,
            page_size: response.page_size,
            data_total: response.data_total
          }
        })
      },

      /** 修改模式分页大小发生改变 */
      handleGridPageSizeChange(size) {
        this.params.page_size = size
        this.GET_PerAccomplishmentTpl()
      },

      /** 修改模式分页页数发生改变 */
      handleGridPageCurrentChange(page) {
        this.params.page_no = page
        this.GET_PerAccomplishmentTpl()
      },

      /** 保存修改模式 */
      reserveTpl() {
        const _params = {
          member_id: this.currentRow.id,
          tpl_id: this.currentRow.current_tpl_id
        }
        API_distribution.modifyTpl(_params).then(() => {
          this.$message.success('修改成功')
          this.GET_DistributorList()
        })
      },

      /** 营业额统计 */
      handleTurnoverStatistics(row) {
        this.$router.push({ path: '/distribution/distributor/distributor-statistics',
          query: { member_id: row.id, member_name: row.name, isAmount: 1 }})
      },

      /** 利润额统计 */
      handleProfitStatistics(row) {
        this.$router.push({ path: '/distribution/distributor/distributor-statistics',
          query: { member_id: row.id, member_name: row.name, isAmount: 2 }})
      },

      // 团长审核弹框
      reviewLeader(val) {
        this.reviewLeaderForm.member_id = val.id;
        this.reviewLeaderDialog = true
      },

      // 修改团长弹框
      auditLeader(val) {
        this.auditLeaderForm = {
          member_id: val.id,
          team_name: val.team_name,
          index_region: val.county_id,
          address: val.address,
          province_id: val.province_id,
          city_id: val.city_id,
          county_id: val.county_id
        }
        this.areas = [
          this.auditLeaderForm.province_id,
          this.auditLeaderForm.city_id,
          this.auditLeaderForm.county_id || -1
        ]
        this.auditLeaderDialog = true
      },

      // 选择框时间
      handleReviewChange(val) {
        let form = this.reviewLeaderForm.audit_status;
        if (form === '2') {
          this.Review = true;
          this.reviewLeaderForm = {
            member_id: this.reviewLeaderForm.member_id,
            audit_status: '2',
            teamName: '',
            index_region: '',
            refuse_reason: ''
          }
        } else {
          this.Review = false;
          this.reviewLeaderForm = {
            member_id: this.reviewLeaderForm.member_id,
            audit_status: '3',
            refuse_reason: ''
          }
        }
      },
      handleClick(reviewLeaderForm) {
        this.$refs[reviewLeaderForm].validate(valide => {
          if (valide) {
            // console.log(this.reviewLeaderForm)
            API_distribution.GETauditDistributor(this.reviewLeaderForm).then(response => {
              this.$message.success(response);
              this.reviewLeaderDialog = false;
              this.GET_DistributorList();
            }).catch((error) => {
              this.$message.error(error)
            })
          }
        })
      },
      // 清除表单
      clearReviewLeader(reviewLeaderForm) {
        this.reviewLeaderDialog = false;
        this.reviewLeaderForm = {
          member_id: '',
          audit_status: '2',
          teamName: '',
          index_region: '',
          refuse_reason: ''
        }
      },
      // 修改团长信息 确定按钮
      auditLeaderClick(auditLeaderForm) {
        this.$refs[auditLeaderForm].validate(valide => {
          if (valide) {
            // console.log(this.auditLeaderForm)
            API_distribution.AuditDisData(this.auditLeaderForm).then(response => {
              console.log(response);
              this.$message.success(response);
              this.auditLeaderDialog = false;
              this.GET_DistributorList();
            }).catch((error) => {
              this.$message.error(error)
            })
          }
        })
      },

      // 级联选择器电击事件
      handleCityChange(val) {
        console.log(val)
      }
    }
  }
</script>

<style type="text/scss" lang="scss" scoped>
  /deep/ .el-table td:not(.is-left) {
    text-align: center;
  }

  .inner-toolbar {
    display: flex;
    width: 100%;
    justify-content: space-between;
    padding: 0 20px;
  }
  /deep/ .modify-model {
    div.toolbar {
      display: none;
    }
  }
  .updat-dialoge {
    color: red;
    margin-bottom: 40px;
  }
  .my-option {
    display: flex;
    justify-content: space-between;
  }
  .myselect-type {
    width: 320px;
  }

/deep/ .el-input-number--small {
  width: 460px;
}
//地图和所在地区组件
/deep/ .app-address {
  width: 100% !important;
  height: 32px;
  .app-address-title {
    padding: 0 20px 0 15px;
    height: 32px;
    line-height: 32px;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #606266;
  }
}
.toolbar-search{
  display: flex;
  flex-flow: row nowrap;
  .cityAddr{
    margin-right: 10px;
    font-size: 12px;
  }
}
</style>




